<template>
	<view class="page-container">
		<!-- 顶部导航栏 -->
		<view class="header">
			<x-status-bar></x-status-bar>
			<view class="flex-center-between header-navbar">
				<x-back-btn></x-back-btn>
				<view class="u-f-40 common-title">
					{{ lang_shop.subscribeList }}
				</view>
			</view>

			<!-- tabs -->
			<v-tabs v-model="tabIndex" :tabs="tabList" activeColor="#333333" lineBottom="12"></v-tabs>
			<!-- 分割线 -->
			<u-gap height="1" bgColor="rgba(0, 0, 0, 0.07)"></u-gap>
		</view>
		<!-- 列表 -->
		<swiper style="height: calc(100vh - 190rpx - var(--status-bar-height))" :current="tabIndex"
			@change="tabIndex = $event.detail.current">
			<swiper-item v-for="(item, index) in tabs" :key="index">
				<subscribe-list ref="mescrollItem" :i="index" :index="tabIndex" :list="tabs" :status-obj="item"
					:reverse-id="reverseId" @change="changeAction"></subscribe-list>
			</swiper-item>
		</swiper>

		<!-- 按钮操作 -->
		<u-modal v-model="visible" :show-title="false" :content="subscribeTips" show-cancel-button
			:cancel-text="lang_common.cancel" :confirm-text="lang_common.done" :confirm-color="'#FD1E43'"
			@confirm="confirmAction" z-index="10203">
		</u-modal>
	</view>
</template>

<script>
	import {
		merchantServiceCancelReverse
	} from '@/api/user/merchantService.js'
	import SubscribeList from './components/subscribe-list.vue'

	export default {
		components: {
			SubscribeList
		},
		data() {
			return {
				tabs: [],
				tabIndex: 0,
				tabValue: 'all',

				visible: false,
				reverseId: ''
			}
		},
		computed: {
			tabList() {
				return this.tabs.map(item => item.title)
			},
			subscribeTips() {
				return this.lang_shop.cancelSubscribeTips || ''
			}
		},
		// 获取类型
		onLoad({
			type
		}) {
			// 初始化顶部导航栏
			let tabs = [{
					key: 'all',
					label: '全部',
					value: ''
				},
				{
					key: 'beConfirmed',
					label: '待确认',
					value: 0
				},
				{
					key: 'rejected',
					label: '已拒绝',
					value: -2
				},
				{
					key: 'beCompleted',
					label: '待完成',
					value: 1
				},
				{
					key: 'canceled',
					label: '已取消',
					value: -1
				},
				{
					key: 'completed',
					label: '已完成',
					value: 2
				},
			].map((item, index) => {
				let result = {
					...item,
					title: !index ? this.lang_common[item.key] : this.lang_shop[item.key]
				}
				return result
			})
			this.tabs = tabs
			if (type) {
				setTimeout(() => {
					this.tabValue = type
				}, 300)
				this.tabIndex = this.tabs.findIndex(item => item.key === type)
			}
		},
		methods: {
			// 按钮触发后
			changeAction({
				reverseId,
				status
			}) {
				this.reverseId = reverseId
				this.visible = true
			},
			// 点击确定后
			confirmAction() {
				let queryObj = {
					reverseId: this.reverseId
				}
				merchantServiceCancelReverse(queryObj).then(() => {
					this.reverseId = ''
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.scroll-container {
		position: relative;
		width: 100vw;
	}

	.tab {
		&-container {
			position: relative;
			padding: 16rpx 0 30rpx;
		}

		&-item {
			position: relative;
			top: 0;
			left: 0;
			padding: 0 48rpx;
			width: max-content;

			&-line {
				position: absolute;
				bottom: -16rpx;
				left: 50%;
				transform: translateX(-50%);
				width: 42rpx;
				height: 8rpx;
				background: #333333;
				border-radius: 10rpx;
			}
		}
	}
</style>
